package com.test.ws.s1.controller;

import com.test.ws.s1.bean.ClassIf;
import com.test.ws.s1.bean.Imgs;
import com.test.ws.s1.bean.Route;
import com.test.ws.s1.service.ClassIfService;
import com.test.ws.s1.service.ImagsService;
import com.test.ws.s1.service.RouteService;
import com.test.ws.s1.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

@Controller
public class ProsceniumController {
    /// 栏目的注入
    @Autowired
    private ClassIfService classIfService;

    /// 旅游线路的注入
    @Autowired
    private RouteService routeService;

    /// 供应商的注入
    @Autowired
    private SupplierService supplierService;

    @Autowired
    private ImagsService imagsService;


    /// 前台首页查询栏目和路由路线
    @RequestMapping("/proscenium")
    public String proscenium(HttpServletRequest request,Route route) {
        /// 栏目查询
        ArrayList<ClassIf> classIfs = classIfService.selectClassIf(null);
        /// 旅游路线查询
        route.setCla_id("1");
        ArrayList<Route> routes = routeService.selectRoute(route);
        route.setCla_id("2");
        ArrayList<Route> routes2 = routeService.selectRoute(route);
        route.setCla_id("3");
        ArrayList<Route> routes3 = routeService.selectRoute(route);
        /// 轮播图查询
        ArrayList<Route> rou = routeService.selectRouteLunBo();


        request.getSession().setAttribute("routeChaZiRan", routes);
        request.getSession().setAttribute("routeChaZhuTi", routes2);
        request.getSession().setAttribute("routeChaMenShi", routes3);

        request.getSession().setAttribute("routeLunBo", rou);
        request.getSession().setAttribute("lanmu", classIfs);
        request.getSession().setAttribute("xianlu", routes);
        return "index";
    }

    /// 显示分类详细数据
    @RequestMapping("/classIfChass")
    public String classIfCha(ClassIf classIf, HttpServletRequest request ,Route route) {
        String id = request.getParameter("id");
        route.setCla_id(id);
        ArrayList<Route> routes = routeService.selectRoute(route);
        request.getSession().setAttribute("xianluFenLei", routes);
        return "fenlei";
    }

    @RequestMapping("/classIfChassa")
    public String classIfChas(ClassIf classIf, HttpServletRequest request ,Route route) {
        String id = request.getParameter("id");
        route.setRoute_id(id);
        /// 主图
        ArrayList<Route> routes = routeService.selectRoute(route);
        /// 附图
        ArrayList<Imgs> imgs = imagsService.selectImgsCha(Integer.parseInt(id));
        System.out.println("附图控制器=================================="+imgs);
        request.getSession().setAttribute("xianluFuTu", imgs);

        request.getSession().setAttribute("xianluTu", routes);
        return "route_detail";
    }

    /// 搜索
    @RequestMapping("/search")
    public String search(HttpServletRequest request,Route route) {
        String action = request.getParameter("action");
        route.setRoute_name(action);
        ArrayList<Route> routes = routeService.selectRoute(route);
        request.getSession().setAttribute("xianluSouSuo", routes);
        return "route_list";
    }
}
